<template>
  <div>
    <!-- 手机修改 -->
    <div class="content">
      <h3 class="user-title">{{'LOGIN_PASS'|t}}</h3>
      <div v-show="defaultIndex==1">
        <!-- 通过手机验证 -->
        <identity-through-mobile @nextStep='nextStep(2)' v-show="queryType=='mobile'"></identity-through-mobile>
        <!-- 通过邮箱验证 -->
        <identity-through-email @nextStep='nextStep(2)' v-show="queryType=='email'"></identity-through-email>
      </div>
      <!-- 邮箱修改 -->
      <div class="form" v-show="defaultIndex==2">
        <zx-form-group :title="$t('PASSWORD')">
          <zx-input v-model="passForm.pass" type="password" :place="$t('PASSWORD_ENTER')" ref="pass" :rules="rules.password">
          </zx-input>
        </zx-form-group>
        <zx-form-group :title="$t('CHECK_PASS')">
          <zx-input v-model="passForm.checkPass" type="password" :place="$t('CHECK_PASS_PLACE')" ref="checkPass" :rules="rules.password">
          </zx-input>
        </zx-form-group>
        <zx-form-group>
          <input type="submit" class="submit-btn mt-20  green-btn radius" :value="$t('COMFIRM')" @click="submitForm('passForm')">
        </zx-form-group>
      </div>
    </div>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex';
  import { Form, Func, Auth, Rules } from '@/providers';
  import { User, UserInfo } from '@/services';
  import identityThroughMobile from '@/components/identity-through-mobile';
  import identityThroughEmail from '@/components/identity-through-email';
  export default {
    data() {
      return {
        defaultIndex: 1,
        queryType: '',
        name: '',
        passForm: {
          pass: '',
          checkPass: ''
        },
        rules: Rules
      };
    },
    methods: {
      // 获取验证码
      getCode(val, type, innerText, event, clickBool) {
        if (this[clickBool]) { return false; };
        if (!Form.validItem(this, type)) { return; };
        this[clickBool] = true;
        if (type == 'phone') {
          Form.SendMobile(val, event.target, clickBool, innerText);
        } else {
          Form.SentMail(val, event.target, clickBool, innerText);
        }
      },
      // 下一步
      async nextStep(formName, step) {
        this.defaultIndex = step;
      },
      // 表单提交
      async submitForm(formName) {
        if (!Form.validataForm(this, formName)) {
          return false;
        }
        let _parmas = this[formName];
        if (_parmas.pass != _parmas.checkPass) {
          this.$dialog.toast({
            msg: this.$t('PASS_CHECK_ERROR'),
            position: 'top'
          });
          return false;
        }
        try {
          let res = await User.UpdateInesvUser({
            password: Func.PasswordEncrypt(_parmas.checkPass),
            userNo: Auth.getItem('userId'),
            token: Auth.getItem('token')
          });
          this.$dialog.toast({
            msg: res.desc,
            position: 'top'
          });
        } catch (error) {
          console.log(error);
        }
      }
    },
    components: {
      'identity-through-mobile': identityThroughMobile,
      'identity-through-email': identityThroughEmail
    },
    created() {
      this.queryType = this.$route.query.type;
    }
  };
</script>
<style scoped lang="scss">
  @import "../../assets/sass/user.scss";
</style>